package com.ray.friendslist.friends;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

import com.ray.friendslist.content.task.CommonTask;
import com.ray.friendslist.content.task.ParamCallback;
import com.ray.friendslist.http.HttpManager;

public class FriendsArray extends CommonTask<List<JSONObject>> {

	private List<JSONObject> mFriendsList;

	public FriendsArray(ParamCallback<List<JSONObject>> paramCallback) {
		super(paramCallback);
		mFriendsList = new ArrayList<JSONObject>();
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<JSONObject> convert(String s) throws Exception {
		// TODO Auto-generated method stub
		JSONObject j=HttpManager.getInstance().loadAsJSONObject(s);
		JSONArray array = j.getJSONArray("response");
		Log.w("ray", "JsonArray created");
		if (array.length() == 0) {
			return null;
		}
		for (int i = 0; i < array.length(); i++) {
			Log.i("ray", array.getJSONObject(i).toString());
			mFriendsList.add(array.getJSONObject(i));
		}
		return mFriendsList;
	}
}
